﻿<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="App=Equipment.Business.Application" %>
<%If App.CurrentUserInfo.RequiredAuthenticationForWorkOrder Then%>
<div id="WorkOrderAuthenticationDialog" class="hidden" title="Authentication">
    <table>
        <tr> 
            <td collspan = "3">
                <p><h2><%= App.CurrentUserInfo.FullName%></h2></p>
            </td>
        </tr>
        <tr>
            <td collspan = "3">
                <p>Please enter your password:</p>
            </td>
        </tr>
        <tr>
            <td collspan = "2">
                <input id ="userpsw" type= "password" class = "text"/>
            </td>
            <td id = "pswerrror">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan = "3">
                <center>
                <input id ="btnOk" type ="submit" value ="     Ok    " class ="button" onclick="CheckAuthentication()" />&nbsp;&nbsp;
                <input id ="btnCancel" type ="reset" value ="  Cancel  " class ="button" onclick="closeAuthenticationDialog()" />
                </center>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    function AuthenticationDialog() {
        $("#WorkOrderAuthenticationDialog").dialog({
            modal: true,
            width: 400,
            height: 250,
            zIndex: 100,
            resizable: false,
            open: function () {
                $("#userpsw").val("");
                $("#pswerrror").html("&nbsp;");
            }
        });
    }

    function AuthenticationForWorkOrder(){
            <% If App.CurrentUserInfo.RequiredAuthenticationForWorkOrder%>
                AuthenticationDialog();    
                return false;
            <%Else %>
                return true; 
            <% End If %>
    }

    function CheckAuthentication(){
        var data = $("#userpsw").val();
        jQuery.ajax({
            type: 'POST',
            async: false,
            data: { psw: data },
            url: '<%= Html.AttributeEncode(Url.Action("CheckAuthentication")) %>',
            success: function (result) {
                if (result) {
                    $("#WorkOrderAuthenticationDialog").dialog("close");
                    $("form:not(#print)").submit();
                }
                else {
                    $("#pswerrror").html("<span class = 'field-validation-error'> Incorrect password </span>");
                    
                }
            },
            error: function () { alert("Error Authentication"); }
        });
    }

    function closeAuthenticationDialog() {
        $("#WorkOrderAuthenticationDialog").dialog("close");
    }

</script>
<%End If%>